package com.smart.upms.sys.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.core.starter.base.BaseController;
import com.smart.core.starter.model.R;
import com.smart.upms.sys.param.SysRoleMenuUpdateParam;
import com.smart.upms.sys.param.SysRoleParam;
import com.smart.upms.sys.param.SysRoleQueryParam;
import com.smart.upms.sys.result.SysRoleResult;
import com.smart.upms.sys.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 角色 前端控制器
 * </p>
 *
 * @author guxiaobai
 * @since 2018-12-05
 */
@Api(description = "角色管理接口")
@RestController
@RequestMapping("/sys/sys-role")
@AllArgsConstructor
public class SysRoleController extends BaseController {
    private final ISysRoleService sysRoleService;


    /**
     * 添加角色
     *
     * @param param 角色信息
     * @return success、false
     */
    @ApiOperation(value = "添加角色")
    @PostMapping
    public R<Boolean> save(@RequestBody SysRoleParam param) {
        return R.success(sysRoleService.save(param));
    }

    /**
     * 修改角色
     *
     * @param param 角色信息
     * @return success/false
     */
    @ApiOperation(value = "修改角色")
    @PutMapping
    public R<Boolean> update(@RequestBody SysRoleParam param) {
        return R.success(sysRoleService.update(param));
    }

    /**
     * 根据id删除
     *
     * @param id id
     * @return success/false
     */
    @ApiOperation(value = "根据id删除")
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable Long id) {
        return R.success(sysRoleService.delete(id));

    }


    /**
     * 通过ID查询
     *
     * @param id ID
     * @return 角色信息
     */
    @ApiOperation(value = "通过ID查询")
    @GetMapping("/{id}")
    public R<SysRoleResult> get(@PathVariable Long id) {
        return R.success(sysRoleService.get(id));
    }


    /**
     * 根据部门id获取角色列表
     *
     * @param deptId 部门ID
     * @return 角色列表
     */
    @GetMapping("/listByDeptId/{deptId}")
    public R<List<SysRoleResult>> listByDeptId(@PathVariable Long deptId) {
        return R.success(sysRoleService.listByDeptId(deptId));
    }


    /**
     * 分页查询
     *
     * @param param 查询对象
     * @return 分页对象
     */
    @ApiOperation(value = "分页查询")
    @GetMapping("/page")
    public R<Page<SysRoleResult>> page(SysRoleQueryParam param) {
        Page<SysRoleResult> page = getPage(param);
        return R.success(sysRoleService.listPage(page, param));
    }

    /**
     * 更新角色菜单
     *
     * @param param 更新参数
     * @return success、false
     */
    @ApiOperation(value = "更新角色菜单")
    @PutMapping("/updateMenu")
    public R<Boolean> updateMenu(@RequestBody SysRoleMenuUpdateParam param) {
        return R.success(sysRoleService.updateMenu(param));

    }


}
